package com.example.projectcode.controller.Admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.projectcode.model.Student;
import com.example.projectcode.model.Teacher;
import com.example.projectcode.result.Result;
import com.example.projectcode.service.StudentService;
import com.example.projectcode.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "后台管理员管理学生端接口")
@RestController
@RequestMapping("/admin")
public class AdminStudentsController {

    @Autowired
    private StudentService studentService;



    /*----------------------学生个人信息管理------------------------------------------*/

    @ApiOperation("添加学生")
    @PostMapping("/insertstudent")
    public Result insertSutdent(@RequestBody Student student)
    {
        if(studentService.insertStudent(student)){
            //添加成功
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    @ApiOperation("分页查询学生")
    @GetMapping("/listStudents/{current}/{size}")
    public Result listStudent(@PathVariable long current,@PathVariable long size){
        Page<Student> page1 = new Page<>(current,size);
        IPage<Student> iPage = studentService.page(page1,null);
        return Result.ok(iPage);
    }

    @ApiOperation("根据学生id删除学生")
    @GetMapping("/deleteStudents/{id}")
    public Result deleteStudent(@PathVariable Integer id){
        if(studentService.deleteStudentById(id)>0){
            return Result.ok();
        }
        return Result.fail();
    }

    @ApiOperation("根据学生id修改个人信息")
    @PostMapping("updateStudent")
    public Result updateStudent(@RequestBody Student student){
        if(studentService.updateStudent(student)>0)
            return Result.ok();
        return Result.fail();
    }




}
